package com.atguigu.gmall.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/8/2 9:56
 */
public class RedisUtil {
    static JedisPool pool;
    
    static {
        JedisPoolConfig conf = new JedisPoolConfig();
        conf.setMaxTotal(300);
        conf.setMaxIdle(10);
        conf.setMaxWaitMillis(10000);
        conf.setMinIdle(4);
        conf.setTestOnCreate(true);
        conf.setTestOnBorrow(true);
        conf.setTestOnReturn(true);
        
        
        pool = new JedisPool(conf, "hadoop162", 6379);
    }
    
    public static Jedis getRedisClient() {
        Jedis jedis = pool.getResource();
//        Jedis jedis = new Jedis("hadoop162", 6379);
        jedis.select(1);
        return jedis;
    }
}
